package cluster;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;

public class Observation<E> implements Comparable{
	public int freq = 1;
	public float relFreq = 0;
	public int cumFreq = 0;
	public float cumRelFreq = 0;
	public E obs;
	
	
	/*	--------------------------------------------------------------
	 * 	Constructors
	 	--------------------------------------------------------------	*/
	public Observation(E obs){
		this.obs = obs;
	}

	/*	--------------------------------------------------------------
	 * 	Getters & Setter
	 	--------------------------------------------------------------	*/
	
	public void set(int f, float rf, int cf, float crf){
		freq = f;
		relFreq = rf;
		cumFreq = cf;
		cumRelFreq = crf;
	}
	
	public void addFreq(){
		freq++;
	}
	public void addFreq(int i){
		freq += i;
	}
	
	public void setFreqs(int total, int before){
		relFreq = (float) freq / (float) total;
		cumFreq = before + freq;
		cumRelFreq = (float) cumFreq / (float) total;
	}
	
	public void setRelFreq(int total){
		relFreq = freq / total;
	}
	
	public void setCumFreq(int before){
		cumFreq = before + freq;
	}

	public int compareTo(Object arg0) {
		Observation<E> o = (Observation<E>)arg0;
		if(freq > o.freq) return 1;
		if(freq < o.freq) return -1;
		return 0;
	}
	
	public ArrayList<E> getObsArray(ArrayList<Observation<E>> list){
		Iterator<Observation<E>> i = list.iterator();
		ArrayList<E> le = new ArrayList<E>(list.size());
		while(i.hasNext()) 
			le.add(i.next().obs);
		return le;
	}
	

	

	
	
	
}
